
var imgs = [

	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/begin_paodao_bg.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/bg_back.jpg",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/end_paodao_bg.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/lottery_btn.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_0.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_1.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_2.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_3.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_4.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_5.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_6.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_7.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_8.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/num_9.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao1.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao2.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao3.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao4.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao5.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao6.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao7.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao8.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao9.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao10.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao11.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/pao12.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/paodao_bg1.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/paodao_bg2.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/power_wrap.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/power.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/repeat_play_btn.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/result_bg.jpg",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/sky_bg1.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/sky_bg2.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/tips1.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/tips2.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/tips3.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/title.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/xingxing_bg.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/zhentou_bg.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/zhentou1.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/zhentou2.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/zhentou3.png",
	"https://gitee.com/charcarron/PaoZhenToudemo/blob/master/img/game/zhentou4.png",
	
];

	var len = imgs.length;
	var count = 1;
	var loadingPage = document.querySelector('.loading');
	var progress = loadingPage.querySelector('.progress');
	for(var i = 1; i <= len; i++){
		var objImg = new Image();
		
		objImg.addEventListener('load',dealData);
		objImg.addEventListener('error',dealData);
		
		objImg.src = imgs[i];
	}
	
	function dealData(){
		if(count >= len){
				loadingPage.style.display = 'none';
				open();
				return false;
			}
		
		progress.innerHTML = 'LOADING...' + Math.round(count / len * 100) + '%';
		count++;
	}
	
	
/*
 * 
 *获取目标枕头 
 * 
 */
	var pillowArr = [
		'img/game/zhentou1.png',
		'img/game/zhentou2.png',
		'img/game/zhentou3.png',
		'img/game/zhentou4.png'
	];
	
	getPillow();
	
	function getPillow(){	//设置枕头
		var pillow = document.querySelector('.pillow');
		var args = getArgs()['pi'];

		//通过本地缓存保存目标枕头的下标
		if(!args){
			args = localStorage.getItem('pillow');
		}else{
			localStorage.setItem('pillow',args);
		}
		pillow.style.background = 'url(' + pillowArr[args] + ') 0 0 no-repeat';
		pillow.style.backgroundSize = '100%';
	}
	function getArgs(){
			var queryUrl = location.search.length > 0? location.search.slice(1) : '';
		
			var args = {};
			
			var argsArr = queryUrl.length? queryUrl.split('&') : [];
			
			var item,name,val;
			
			for(var i = 0; i < argsArr.length; i++){
				item = argsArr[i].split('=');
				name = decodeURI(item[0]);
				val = decodeURI(item[1]);
				
				args[name] = val;
			}
			
			return args;
	}
	